<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <el-button type="primary" @click="opSendApply" v-if="orgType == 1">添加</el-button>
                <el-button
                    v-if="orgType==1"
                    type="primary"
                    icon="el-icon-plus"
                    @click="opBatchImportJd"
                >批量导出金蝶</el-button>
            </div>
            <div class="right-panel">
                <el-button :icon="Search"   type="primary" @click="opBindData">查询</el-button>
                <el-button :icon="Search" type="info" plain @click="resetSearch">重置</el-button>
                <el-button text type="primary" @click="showCondition = !showCondition">
                    <span v-if="!showCondition">展开</span>
                    <span v-else>收起</span>
                    <vab-icon
                        class="vab-dropdown"
                        :class="{ 'vab-dropdown-active': fold }"
                        icon="arrow-up-s-line"
                    />
                </el-button>
            </div>
        </el-header>
        <el-foot v-show="showCondition">
            <vab-query-form-top-panel>
                <el-form inline label-width="49px" :model="queryForm" style="margin-top: 5px">
                    <el-form-item label="对账时间" label-width="100px">
                        <el-date-picker
                            style="width: 300px"
                            v-model="queryList.times"
                            type="datetimerange"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="-"
                            unlink-panels="true"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            :default-time="defaultTime"
                        />
                    </el-form-item>
                    <el-form-item label="对账申请编号" label-width="100px">
                        <el-input
                            placeholder="---请输入对账申请编号---"
                            v-model="queryList.storageOrderAccountCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="对账申请日期" label-width="100px">
                        <el-date-picker
                            style="width: 300px"
                            v-model="queryList.StorageOrderAccountTimes"
                            type="datetimerange"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="-"
                            unlink-panels="true"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            :default-time="defaultTime"
                        />
                    </el-form-item>

                    <el-form-item label="申请人" label-width="100px">
                        <el-input
                            placeholder="---请输入申请人---"
                            v-model="queryList.applicantUser"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="联系电话" label-width="100px">
                        <el-input
                            placeholder="---请输入联系电话---"
                            v-model="queryList.tel"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="对账状态" label-width="100px" v-if="orgType==1">
                        <el-select
                            placeholder="---请选择状态---"
                            v-model="queryList.wineStatusList"
                            style="width: 300px"
                        >
                            <el-option label="---请选择状态---" value />
                            <el-option
                                v-for="item in optionsState"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="对账状态" label-width="100px" v-if="orgType==3">
                        <el-select
                            placeholder="---请选择状态---"
                            v-model="queryList.supplierStatus"
                            style="width: 300px"
                        >
                            <el-option label="---请选择状态---" value />
                            <el-option
                                v-for="item in optionsState"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="对账申请单位" label-width="100px" v-if="this.orgType==1">
                        <el-input
                            placeholder="---请输入对账申请单位---"
                            v-model="queryList.supplierName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料简码" label-width="100px">
                        <el-input
                            placeholder="---请输入物料简码---"
                            v-model="queryList.MaterialSimpCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料编号" label-width="100px">
                        <el-input
                            placeholder="---请输入物料编号---"
                            v-model="queryList.MaterialCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料分类" label-width="100px">
                        <el-tree-select
                            v-model="queryList.MaterialTypeIds"
                            placeholder="---请选择物料分类---"
                            :props="{ label: 'label', value:'value',children: 'children' }"
                            :data="materialTypeTree"
                            multiple
                            :render-after-expand="false"
                            show-checkbox
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料名称" label-width="100px">
                        <el-input
                            placeholder="---请输入物料名称---"
                            v-model="queryList.MaterialName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="规格型号" label-width="100px">
                        <el-input
                            placeholder="---请输入规格型号---"
                            v-model="queryList.MaterialSpecs"
                            style="width: 300px"
                        />
                    </el-form-item>
                </el-form>
            </vab-query-form-top-panel>
        </el-foot>

        <el-main class="nopadding">
            <scTable
                ref="mytable"
                :span-method="objectSpanMethod"
                border
                :queryType="'storage-order-account/pages'"
                :data="listData"
                :queryList="queryList"
                :column="columnList"
                :orderList="OrderList"
                :sort-orders="['ascending', 'descending']"
                @selection-change="selectionChange"
                :row-class-name="setRowClass"
                :isKeyDown="showCondition"
                row-key="ReceivingOrderId"
                key="ReceivingOrderId"
                show-summary
                remoteSummary
            >
                <el-table-column type="selection" width="50"></el-table-column> 
                <el-table-column label="序号" type="index" width="80"></el-table-column>
                <el-table-column label="对账日期" prop="accountStartDate" width="200" sortable>
                    <!-- <template #default="scope">
						<div>{{ scope.row.accountStartDate }} - {{ scope.row.accountEndDate }}</div>
                    </template>-->
                    <template #default="scope">
                        {{scope.row.accountStartDate? scope.row.accountStartDate.slice(0, 10):scope.row.accountStartDate}}
                        {{'-'}}
                        {{scope.row.accountEndDate? scope.row.accountEndDate.slice(0, 10):scope.row.accountEndDate}}
                    </template>
                </el-table-column>
                <el-table-column label="对账申请编号" prop="storageOrderAccountCode" width="200" sortable>
                    <template #default="scope">
                        <span
                            class="el-span-text"
                            @click="openBIgTable(scope.row, scope.$index)"
                        >{{scope.row.storageOrderAccountCode}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="对账状态"
                    prop="wineStatusDesc"
                    width="110"
                    v-if="this.orgType==1"
                    sortable
                >
                    <template #default="scope">
                        <span
                            v-if="scope.row.wineStatus==0"
                            style="color:red"
                        >{{ scope.row.wineStatusDesc }}</span>
                        <span
                            v-else-if="scope.row.wineStatus==1"
                            style="color:#409EFF"
                        >{{ scope.row.wineStatusDesc }}</span>
                        <span
                            v-else-if="scope.row.wineStatus==2"
                            style="color:green"
                        >{{ scope.row.wineStatusDesc }}</span>
                        <span v-else-if="scope.row.wineStatus==3">已收到申请</span>
                        <span v-else-if="scope.row.wineStatus==4" style="color:#909399">已关账</span>
                        <span v-else>{{ scope.row.wineStatusDesc }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="对账状态"
                    prop="supplierStatusDesc"
                    width="110"
                    v-if="this.orgType==3"
                    sortable
                >
                    <template #default="scope">
                        <span
                            v-if="scope.row.supplierStatus==0"
                            style="color:red"
                        >{{ scope.row.supplierStatusDesc }}</span>
                        <span
                            v-else-if="scope.row.supplierStatus==1"
                            style="color:#409EFF"
                        >{{ scope.row.supplierStatusDesc }}</span>
                        <span
                            v-else-if="scope.row.supplierStatus==2"
                            style="color:green"
                        >{{ scope.row.supplierStatusDesc }}</span>
                        <span v-else-if="scope.row.supplierStatus==3">已发送申请</span>
                        <span v-else-if="scope.row.supplierStatus==4" style="color:#909399">已关账</span>
                        <span v-else>{{ scope.row.supplierStatusDesc }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="对账申请日期" prop="storageOrderAccountTime" sortable></el-table-column>
                <el-table-column label="对账申请单位" prop="supplierFullName" sortable></el-table-column>
                <el-table-column label="申请人" prop="applicantUser" width="100" sortable></el-table-column>
                <el-table-column label="对账单位" prop="purchaseUnityName" width="110" sortable></el-table-column>
                <el-table-column label="联系电话" prop="tel" width="150" sortable></el-table-column>

                <!-- <el-table-column label="对账明细表" fixed="right" prop="materialCode" width="150">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small"
								@click="openBIgTable(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small"
								@click="opDown(scope.row, scope.$index)">下载</el-button>
							<el-button text type="primary" size="small" @click="openBIgTable(scope.row, scope.$index)">预览</el-button>
							<el-button text type="primary" size="small" @click="openBIgTable(scope.row, scope.$index)">打印</el-button>
						</el-button-group>
					</template>
                </el-table-column>-->
                <!-- 	<el-table-column label="相关附件" fixed="right" prop="accountFile" width="150">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small"
								@click="opPreview(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small"
								@click="opDownFile(scope.row, scope.$index)">下载</el-button>
						</el-button-group>
					</template>
                </el-table-column>-->

                <el-table-column
                    label="操作"
                    fixed="right"
                    align="center"
                    width="200"
                    v-if="orgType==1"
                >
                    <template #default="scope">
                        <el-button-group>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                @click="openBIgTable(scope.row, scope.$index)"
                            >明细查看</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                @click="opDown(scope.row, scope.$index)"
                            >明细下载</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                @click="opPreview(scope.row, scope.$index)"
                            >附件查看</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                @click="opDownFile(scope.row, scope.$index)"
                            >附件下载</el-button>
                            <el-button
                                text
                                type="success"
                                size="small"
                                @click="opEnd(scope.row, scope.$index)"
                                v-if="scope.row.wineStatus!=2"
                            >结束对账</el-button>
                            <!-- <el-button text type="primary" size="small"
								@click="startReconciliation(scope.row, scope.$index)"
                            v-if="scope.row.wineStatus==3">开始对账</el-button>-->
                            <el-button
                                text
                                type="success"
                                size="small"
                                @click="opCheck(scope.row, scope.$index)"
                                v-if="scope.row.wineStatus==1||scope.row.wineStatus==3"
                            >进行对账</el-button>
                            <el-button
                                text
                                type="warning"
                                size="small"
                                v-if="orgType==1 && scope.row.wineStatus==2 && !scope.row.isImportJd"
                                @click="opAntiAudit(scope.row, scope.$index)"
                            >反 审 核&nbsp;</el-button>
                            <el-button
                                text
                                type="warning"
                                size="small"
                                v-if="orgType==1 && scope.row.wineStatus==2"
                                @click="opImportJd([scope.row.storageOrderAccountId])"
                            >金蝶导出</el-button>
                            <el-button
                                v-if="scope.row.wineStatus==1||scope.row.wineStatus==3"
                                text
                                type="danger"
                                size="small"
                                @click="openDel(scope.row)"
                            >&nbsp;删&nbsp;&nbsp;&nbsp;除</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>

                <el-table-column
                    label="应付账款"
                    fixed="right"
                    align="center"
                    width="100"
                    v-if="orgType==1"
                >
                    <template #default="scope">
                        <el-button-group>
                            <el-button
                                text
                                type="success"
                                size="small"
                                @click="createBill(scope.row, scope.$index)"
                                v-if="scope.row.wineStatus==2 && scope.row.isCreateBill==0"
                            >生成</el-button>
                            <el-button text type="success" size="small" v-else>---</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>

                <el-table-column
                    label="操作"
                    fixed="right"
                    align="center"
                    width="200"
                    v-if="orgType==3"
                >
                    <template #default="scope">
                        <el-button-group>
                            <!-- <el-button text type="primary" size="small" @click="opEdit(scope.row, scope.$index)"
                            v-if="scope.row.supplierStatus!=2">编辑申请</el-button>-->
                            <el-button
                                text
                                type="success"
                                size="small"
                                @click="opCheck(scope.row, scope.$index)"
                                v-if="scope.row.supplierStatus==1||scope.row.supplierStatus==3"
                            >进行对账</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <check-dialog
        v-if="dialogCheck"
        ref="checkDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogCheck = false"
    ></check-dialog>
    <print-dialog v-if="dialogPrint" ref="printDialog" @closed="dialogPrint = false"></print-dialog>
    <send-apply-dialog
        v-if="dialogSendApply"
        ref="sendApplyObj"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogSendApply = false"
    ></send-apply-dialog>
    <office-dialog ref="officeDialog" />
    <detail-table
        v-if="visibleBig"
        ref="visibleBig"
        @fatherMethod="opBindData"
        @checkTable="checkTable"
        @success="handleSaveSuccess"
        @closed="visibleBig = false"
    ></detail-table>
    <sales-check v-if="salesCheckShow" ref="salesCheck" @closed="salesCheckShow = false"></sales-check>
</template>

<script>
import publicjs from "@/api/model/publicjs";
import tool from "@/utils/tool";

import sendApplyDialog from "./sendApply"; // 对账申请
import detailTable from "./detailTable"; // 对账明细表
import officeDialog from "./components/officeViewer";
import salesCheck from "./components/salesCheck";
export default {
    components: {
        publicjs,
        sendApplyDialog,
        detailTable,
        officeDialog,
        salesCheck,
    },
    data() {
        return {
            orgType: "",
            columnList: [],
            queryList: {},
            selectionRows: [],
            showCondition: false,
            columnIndex0: "",
            columnIndex17: "",
            columnIndex15: "",
            dialogPrint: false,
            dialogCheck: false,
            dialogSendApply: false,
            visibleBig: false,
            previewImageUrl: "",
            isDownLoad: false,
            salesCheckShow: false,
            defaultTime: [
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 2, 1, 23, 59, 59),
            ],
            optionsState: [
                {
                    value: 2,
                    label: "已对账",
                },
                {
                    value: 0,
                    label: "未对账",
                },
                {
                    value: 1,
                    label: "对账中",
                },
                {
                    value: 3,
                    label: "已发送申请",
                },
                {
                    value: 4,
                    label: "已关账",
                },
            ],
        };
    },
    methods: {
        async opBindData() {
            this.$refs.mytable.clearSort();
            this.$refs.mytable.getData();
        },
        async opEnd(row) {
            try {
                var response = await this.$API.auth.PostProcessApi.post(
                    "storage-order-account/isAllCheck",
                    row
                );
                console.log(response);

                if (response.status == 200) {
                    this.$confirm(response.msg + ",是否继续?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(async () => {
                        var endresponse =
                            await this.$API.auth.PostProcessApi.post(
                                "storage-order-account/endAccount",
                                row
                            );
                        if (endresponse.status == 200) {
                            this.$message.success("结束账单成功");
                            this.opBindData();
                        } else {
                            this.$message.error(endresponse.message);
                        }
                    });
                } else {
                    this.$message.error(response.message);
                }
            } catch (error) {
                this.loading = false;
                this.$message.error(error.message);
                return false;
            }
        },
        resetSearch() {
            this.queryList = {};
        },
        openBIgTable(row) {
            console.log("openBIgTable...", this.selectionRows);

            this.visibleBig = true;
            this.$nextTick(() => {
                this.$refs.visibleBig.initData(row);
            });
        },
        async opDown(row) {
            let arr = [];
            arr.push(row.storageOrderAccountId);
            try {
                await this.$API.auth.PostProcessApi.post(
                    `storage-order-account/download`,
                    {
                        storageOrderAccountIds: arr,
                    },
                    {
                        responseType: "blob",
                    }
                )
                    .then((res) => {
                        this.downloadfile(res);
                    })
                    .catch((err) => {
                        this.$message.error("下载错误：获取文件流错误");
                    });
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //金蝶批量导出
        async opBatchImportJd() {
            if (this.selectionRows.length == 0) {
                this.$message.error("请选择要导出的单据");
                return;
            }
           const storageOrderAccountIds= this.selectionRows.map((row) =>row.storageOrderAccountId);
           await this.opImportJd(storageOrderAccountIds);
        },
        //金蝶导出
        async opImportJd(storageOrderAccountIds){
            try {
                var response = await this.$API.auth.PostProcessApi.post(`storage-order-account/import-jd-detail`,{storageOrderAccountIds:storageOrderAccountIds});
                if (response.status == 200) {
                    if(response.response.purchaseStorageOrderIds&&response.response.purchaseStorageOrderIds.length>0){
                        await this.$API.auth.PostDownApi.post("storage-order/down-jd-file",{storageOrderIds:response.response.purchaseStorageOrderIds}).then((res)=>
                        {
                            this.downloadfile(res.data);
                        }).catch((err) => {
                            this.$message.error('下载错误：获取文件流错误')
                        });
                    }

                    if(response.response.afterStorageOrderIds&&response.response.afterStorageOrderIds.length>0){
                        await this.$API.auth.PostDownApi.post("storage-order/down-jdtk-file",{storageOrderIds:response.response.afterStorageOrderIds}).then((res)=>
                        {
                            this.downloadfile(res.data);
                        }).catch((err) => {
                            this.$message.error('下载错误：获取文件流错误')
                        });
                    }
                } else {
                    this.$message.error("操作失败:" + response.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        downloadfile(blob) {
            console.log("res", blob);
            let fileReader = new FileReader();
            //var blob = new Blob([res], {type: 'application/octet-stream;charset=UTF-8'})
            fileReader.onload = function () {
                try {
                    var downloadElement = document.createElement("a");
                    var href = window.URL.createObjectURL(blob); // 创建下载的链接
                    downloadElement.style.display = "none";
                    downloadElement.href = href;
                    downloadElement.download = decodeURI("明细.xlsx"); // 下载后文件名
                    document.body.appendChild(downloadElement);
                    downloadElement.click(); // 点击下载
                    document.body.removeChild(downloadElement); // 下载完成移除元素
                    window.URL.revokeObjectURL(href);
                } catch (err) {
                    console.log(err);
                }
            };
            fileReader.readAsText(blob);
        },
        setRowClass({ row }) {
            if (this.selectionRows.includes(row)) {
                return "selected-row-color";
            }
            return "";
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selectionRows = selection;
            console.log(this.selectionRows);
        },
        //开始对账
        async startReconciliation(row) {
            try {
                await this.$API.auth.PostProcessApi.post(
                    "storage-order-account/startReconciliation",
                    { storageOrderAccountId: row.storageOrderAccountId }
                ).then((returnValue) => {
                    if (returnValue.status == 200) {
                        //this.opBindData();
                    } else {
                        this.opBindData();
                        this.$message.error("操作失败:" + returnValue.msg);
                    }
                });
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        // 进行对账
        async opCheck(row) {
            this.salesCheckShow = true;

            this.$nextTick(() => {
                this.$refs.salesCheck.setData(row);
                this.$refs.salesCheck.open();
                this.startReconciliation(row);
            });
        },
        //编辑申请
        opEdit(row) {
            this.dialogSendApply = true;
            this.$nextTick(() => {
                this.$refs.sendApplyObj.setData(row, "Edit");
                this.$refs.sendApplyObj.open("Edit");
            });
        },
        //删除
        async openDel(row) {
            this.$confirm("删除后无法恢复,确认要删除？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(async () => {
                    try {
                        var response = await this.$API.auth.PostDownApi.post(
                            "storage-order-account/del",
                            {
                                storageOrderAccountId: row.storageOrderAccountId,
                            }
                        );
                        if (response.status == 200) {
                            this.opBindData();
                        } else {
                            this.$message.error("操作失败:" + response.msg);
                        }
                    } catch (error) {
                        this.loading = false;
                        this.$message.error(error.message);
                        return false;
                    }
                })
                .catch(() => {
                    // 用户点击了取消按钮，不执行关闭
                });
        },
        async opPrintview(row) {
            let arr = [];
            arr.push(row.storageOrderAccountId);
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "storage-order-account/items",
                    {
                        storageOrderAccountIds: arr,
                    }
                );
                if (returnValue.status == 200) {
                    this.dialogPrint = true;
                    this.$nextTick(() => {
                        this.$refs.printDialog.setData(returnValue.response);
                        this.$refs.printDialog.open("Show");
                    });
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        opDownFile(row) {
            if (row.accountFile == null || row.accountFile.length <= 0) {
                this.$message.error("暂无附件");
            } else {
                const url = new URL(row.accountFile);
                const fileName = url.pathname.split("/").pop(); // 获取文件名
                fetch(row.accountFile)
                    .then((response) => response.blob())
                    .then((blob) => {
                        const url = URL.createObjectURL(blob);
                        const a = document.createElement("a");
                        a.style.display = "none";
                        a.href = url;
                        a.download = fileName;
                        document.body.appendChild(a);
                        a.click();
                        window.URL.revokeObjectURL(url);
                    })
                    .catch((error) => console.error("下载失败:", error));
            }
        },
        opPreview(row) {
            // 预览操作，打开对话框显示图片
            this.$refs.officeDialog.setData(row.accountFile);
            this.$refs.officeDialog.open();
        },
        //反审核
        opAntiAudit(row) {
            this.$confirm("是否反审核?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(async () => {
                    try {
                        var response = await this.$API.auth.PostDownApi.post(
                            "storage-order-account/antiAudit",
                            {
                                storageOrderAccountId: row.storageOrderAccountId,
                            }
                        );
                        if (response.status == 200) {
                            this.opBindData();
                        } else {    
                            this.$message.error("操作失败:" + response.msg);
                        }
                    } catch (error) {
                        this.loading = false;
                        this.$message.error(error.message);
                        return false;
                    }
                })
                .catch(() => {});
                // 用户点击了取消按钮，不执行关闭
        },
        //生成应付账单
        async createBill(row) {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "storage-order-account/createBill",
                    {
                        storageOrderAccountId: row.storageOrderAccountId,
                    }
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    await this.opBindData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //查看
        opShow(row) {
            this.dialogCheck = true;
            this.$nextTick(() => {
                this.$refs.checkDialog.setData(row);
                this.$refs.checkDialog.open("Show");
            });
        },
        allprintview() {
            if (this.selectionRows.length > 0) {
                this.dialogPrint = true;
                let uniqueArr = this.selectionRows.filter(
                    (item, index, self) =>
                        index ===
                        self.findIndex(
                            (t) => t.receivingOrderId === item.receivingOrderId
                        )
                );
                this.$nextTick(() => {
                    this.$refs.printDialog.setData(uniqueArr);
                    this.$refs.printDialog.open("Show");
                });
            } else {
                this.$message.error("请选择要打印的数据");
            }
        },
        async allaccount() {
            if (this.selectionRows.length > 0) {
                let uniqueArr = this.selectionRows.filter(
                    (item, index, self) =>
                        index ===
                        self.findIndex(
                            (t) => t.receivingOrderId === item.receivingOrderId
                        )
                );
                var ids = uniqueArr.map((item) => {
                    return item.receivingOrderId;
                });
                const returnValue = await this.$API.auth.PostProcessApi.post(
                    "receiving-order/account",
                    ids
                );
                if (returnValue.status == 200) {
                    this.$message.success(returnValue.msg);
                    await this.opBindData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } else {
                this.$message.error("请选择要对账的数据");
            }
        },
        //打开对账申请对话框
        opSendApply() {
            this.dialogSendApply = true;
            this.$nextTick(() => {
                this.$refs.sendApplyObj.setData();
                this.$refs.sendApplyObj.open("Send");
            });
        },
        objectSpanMethod({ row, column, rowIndex, columnIndex }) {},
    },
    // 监听
    watch: {
        salesCheckShow: {
            handler(newValue, oldValue) {
                if (!newValue) {
                    this.opBindData();
                }
            },
            deep: true,
        },
    },
    async mounted() {
        this.orgType = tool.data.get("USER_INFO").AccountType;
        if (this.orgType == 3) {
            this.queryList.SupplierId = tool.data.get("USER_INFO").OrgId;
        }
        await this.opBindData();
    },
};
</script>

<style lang="scss" scoped>
/* 当表格行处于悬停状态时改变背景颜色 */
::v-deep .el-table .el-table__row:hover {
    background-color: #dae8f7;
}
::v-deep .el-table__body .el-table__row--striped.hover-row td {
    background-color: #dae8f7 !important;
}
//   斑马纹选中颜色
::v-deep .el-table__body .el-table__row--striped.selected-row-color td {
    background-color: #b8dcff !important;
}
::v-deep .el-table {
    --el-table-row-hover-bg-color: #dae8f7;
}

::v-deep .el-table tr:nth-child(2n) {
    background: #f2f2f2;
}
</style>
<style>
.el-table .selected-row-color {
    background-color: #b8dcff !important;
}
.el-table--enable-row-hover .el-table__body tr.selected-row-color:hover > td {
    background-color: #b8dcff !important;
}
.el-table__body-wrapper .el-table__body tr.selected-row-color.hover-row > td {
    background-color: #b8dcff !important;
}
.el-table__fixed-body-wrapper
    .el-table__body
    tr.selected-row-color.hover-row
    > td {
    background-color: #b8dcff !important;
}
.el-table__body-wrapper
    .el-table__body
    tr.selected-row-color.hover-row
    > .el-table__row--striped {
    background-color: #b8dcff !important;
}
</style>
